﻿using MeetingRoomBooking.Application.Common.Interfaces;

namespace MeetingRoomBooking.Application.Rooms.Commands;
public class DeleteUserCommand:IRequest
{
    public int Id { get; set; }
}

public class DeleteUserCommandHander : IRequestHandler<DeleteUserCommand>
{
    private readonly IApplicationDbContext _context;  

    public DeleteUserCommandHander(IApplicationDbContext context)
    {
        _context = context;     
    }    

    public async Task Handle(DeleteUserCommand request, CancellationToken cancellationToken)
    {
        var user = await _context.Users.FindAsync(request.Id);
       
        if (user == null) throw new Exception($"User Id:{request.Id} not found.");

        _context.Users.Remove(user);

       // user.AddDomainEvent(new RoomCreatedEvent(user));        

        await _context.SaveChangesAsync(cancellationToken);          
    }
}
